package com.mgfireworks.mgplatform.mgadmin.product;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.mgfireworks.mgplatform.mgadmin.product.model.Category;

import cn.hn.java.summer.annotation.ParamValid;

/**
 * 
 * @author nap
 * 20161015-10:19:48
 * 产品类别控制器
 */
@Controller
@RequestMapping("/product/category")
public class CategoryController {

	@Autowired
	CategoryService categoryService;
	
	/**
	 * 产品类别列表
	 * @return
	 */
	@RequestMapping("/list")
	public List<Category> list(Category p){
		return categoryService.getProductCategorys(p);
	}

	/**
	 * 添加产品类别
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public Category add(int catId){
		return categoryService.newCategory(catId);
	}
	
	/**
	 * 提交添加产品类别
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public void postAdd(@ParamValid Category p){
		categoryService.addProductCategory(p);
	}

	/**
	 * 编辑产品类别
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public Category edit(Category p){
		return categoryService.getProductCategory(p);
	}
	
	/**
	 * 提交编辑产品类别
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	public void postEdit(@ParamValid Category p){
		categoryService.editProductCategory(p);
	}
	
	/**
	 * 获取产品类别
	 */
	@RequestMapping(value="/get",method=RequestMethod.GET)
	public Category get(Category p){
		return categoryService.getProductCategory(p);
	}
	
	/**
	 * 删除产品类别
	 */
	@RequestMapping("/del")
	public void del(Category p){
		categoryService.delProductCategory(p);
	}
}